﻿using System;
using Assets.Scripts.GtsScripts;
using UnityEngine;

// Token: 0x020002D6 RID: 726
public class Wind : MonoBehaviour
{
	// Token: 0x060010E9 RID: 4329 RVA: 0x0007C30C File Offset: 0x0007A50C
	private void Start()
	{
		this.anim = base.gameObject.GetComponent<Animator>();
		this.player = GameController.playerInstance;
		this.giantess = base.GetComponent<Giantess>();
		this.animationSpeedHash = Animator.StringToHash("animationSpeed");
		Transform boneTransform = this.anim.GetBoneTransform(HumanBodyBones.LeftHand);
		if (boneTransform)
		{
			this.Lhand = boneTransform;
			this.L2hand = this.Lhand.position;
			if (!Wind.handwind)
			{
				Wind.handwind = Resources.Load<AudioClip>("Sound/Giantess/windhands");
			}
			this.lefthandSource = this.CreateAudioSource(boneTransform);
			this.lefthandSource.clip = Wind.handwind;
			this.lefthandSource.Play();
		}
		Transform boneTransform2 = this.anim.GetBoneTransform(HumanBodyBones.RightHand);
		if (boneTransform2)
		{
			this.Rhand = boneTransform2;
			this.R2hand = this.Rhand.position;
			if (!Wind.handwind)
			{
				Wind.handwind = Resources.Load<AudioClip>("Sound/Giantess/windhands");
			}
			this.righthandSource = this.CreateAudioSource(boneTransform2);
			this.righthandSource.clip = Wind.handwind;
			this.righthandSource.Play();
		}
		Transform boneTransform3 = this.anim.GetBoneTransform(HumanBodyBones.LeftFoot);
		if (boneTransform3)
		{
			this.Lfoot = boneTransform3;
			this.L2foot = this.Lfoot.position;
			if (!Wind.footwind)
			{
				Wind.footwind = Resources.Load<AudioClip>("Sound/Giantess/windfeet");
			}
			this.leftfootSource = this.CreateAudioSource(boneTransform3);
			this.leftfootSource.clip = Wind.footwind;
			this.leftfootSource.Play();
		}
		Transform boneTransform4 = this.anim.GetBoneTransform(HumanBodyBones.RightFoot);
		if (boneTransform4)
		{
			this.Rfoot = boneTransform4;
			this.R2foot = this.Rfoot.position;
			if (!Wind.footwind)
			{
				Wind.footwind = Resources.Load<AudioClip>("Sound/Giantess/windfeet");
			}
			this.rightfootSource = this.CreateAudioSource(boneTransform4);
			this.rightfootSource.clip = Wind.footwind;
			this.rightfootSource.Play();
		}
		Transform boneTransform5 = this.anim.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
		if (boneTransform5)
		{
			this.Lleg = boneTransform5;
			this.L2leg = this.Lleg.position;
			if (!Wind.legwind)
			{
				Wind.legwind = Resources.Load<AudioClip>("Sound/Giantess/windlegs");
			}
			this.leftlegSource = this.CreateAudioSource(boneTransform5);
			this.leftlegSource.clip = Wind.legwind;
			this.leftlegSource.Play();
		}
		Transform boneTransform6 = this.anim.GetBoneTransform(HumanBodyBones.RightLowerLeg);
		if (boneTransform6)
		{
			this.Rleg = boneTransform6;
			this.R2leg = this.Rleg.position;
			if (!Wind.legwind)
			{
				Wind.legwind = Resources.Load<AudioClip>("Sound/Giantess/windlegs");
			}
			this.rightlegSource = this.CreateAudioSource(boneTransform6);
			this.rightlegSource.clip = Wind.legwind;
			this.rightlegSource.Play();
		}
		Transform boneTransform7 = this.anim.GetBoneTransform(HumanBodyBones.Hips);
		if (boneTransform7)
		{
			this.Thips = boneTransform7;
			this.T2hips = this.Thips.position;
			if (!Wind.hipwind)
			{
				Wind.hipwind = Resources.Load<AudioClip>("Sound/Giantess/windhips");
			}
			this.hipSource = this.CreateAudioSource(boneTransform7);
			this.hipSource.clip = Wind.hipwind;
			this.hipSource.Play();
		}
		Transform boneTransform8 = this.anim.GetBoneTransform(HumanBodyBones.Head);
		if (boneTransform8)
		{
			this.Thead = boneTransform8;
			this.headRotation = boneTransform8.rotation;
			if (!Wind.headwind)
			{
				Wind.headwind = Resources.Load<AudioClip>("Sound/Giantess/windhead");
			}
			this.headSource = this.CreateAudioSource(boneTransform8);
			this.headSource.clip = Wind.headwind;
			this.headSource.Play();
		}
		Transform boneTransform9 = this.anim.GetBoneTransform(HumanBodyBones.Chest);
		if (boneTransform9)
		{
			this.Tchest = boneTransform9;
			this.T2chest = boneTransform9.position;
			if (!Wind.chestwind)
			{
				Wind.chestwind = Resources.Load<AudioClip>("Sound/Giantess/windbreasts");
			}
			this.chestSource = this.CreateAudioSource(boneTransform9);
			this.chestSource.clip = Wind.chestwind;
			this.chestSource.Play();
		}
	}

	// Token: 0x060010EA RID: 4330 RVA: 0x0007C788 File Offset: 0x0007A988
	private void Mute()
	{
		if (this.hipSource)
		{
			this.hipSource.volume = 0f;
		}
		if (this.headSource)
		{
			this.headSource.volume = 0f;
		}
		if (this.chestSource)
		{
			this.chestSource.volume = 0f;
		}
		if (this.lefthandSource)
		{
			this.lefthandSource.volume = 0f;
		}
		if (this.righthandSource)
		{
			this.righthandSource.volume = 0f;
		}
		if (this.leftfootSource)
		{
			this.leftfootSource.volume = 0f;
		}
		if (this.rightfootSource)
		{
			this.rightfootSource.volume = 0f;
		}
		if (this.leftlegSource)
		{
			this.leftlegSource.volume = 0f;
		}
		if (this.rightlegSource)
		{
			this.rightlegSource.volume = 0f;
		}
	}

	// Token: 0x060010EB RID: 4331 RVA: 0x0007C8B8 File Offset: 0x0007AAB8
	private void FixedUpdate()
	{
		if (this.player == null)
		{
			this.player = GameController.playerInstance;
		}
		if (this.giantess.poseMode || SoundManager.windVolume <= 0f)
		{
			this.Mute();
			return;
		}
		this.scale = base.transform.localScale.y;
		this.size = this.Lhand.lossyScale.y * 1000f;
		this.speed = Mathf.Clamp(0.175f, this.anim.GetFloat(this.animationSpeedHash), this.size);
		this.modifier = Mathf.Pow(this.speed, 2f) * this.size;
		this.relationship = (1f - this.player.Scale * 2.5f / this.size) * SoundManager.windVolume;
		this.pitchAdjust = 1f / Mathf.Sqrt(this.size / 125f + 1f);
		this.modpitch = 0.75f * this.pitchAdjust + 0.9f;
		this.legpitch = 1.1f * this.pitchAdjust + 0.9f;
		this.headpitch = 0.9f * this.pitchAdjust + 0.9f;
		float num = 0f;
		if (this.hipSource)
		{
			this.hipDisplacement = Vector3.Distance(this.T2hips, this.Thips.position) / this.modifier;
			this.T2hips = this.Thips.position;
			this.hipSource.maxDistance = this.hipDistance * this.scale;
			this.hipSource.minDistance = this.hipSource.maxDistance * this.minDistancePercentage;
			this.hipSource.pitch = this.legpitch;
			this.hipSource.volume = Mathf.Lerp(this.hipSource.volume, this.relationship * 20f * (this.hipDisplacement - 0.001f), Time.deltaTime * 8f);
			num += this.hipSource.volume;
			if (num > 1f)
			{
				return;
			}
		}
		if (this.headSource)
		{
			this.headRotationalDisplacement = Quaternion.Angle(this.headRotation, this.Thead.localRotation) / (this.modifier / this.size * 180f);
			this.headRotation = this.Thead.localRotation;
			this.headSource.maxDistance = this.headDistance * this.scale;
			this.headSource.minDistance = this.headSource.maxDistance * this.minDistancePercentage;
			this.headSource.pitch = this.headpitch;
			this.headSource.volume = Mathf.Lerp(this.headSource.volume, this.relationship * 22f * (this.headRotationalDisplacement - 0.00325f), Time.deltaTime * 8f);
			num += this.hipSource.volume;
		}
		if (this.chestSource)
		{
			this.chestDisplacement = Vector3.Distance(this.T2chest, this.Tchest.position) / this.modifier;
			this.T2chest = this.Tchest.position;
			this.chestSource.maxDistance = this.chestDistance * this.scale;
			this.chestSource.minDistance = this.hipSource.maxDistance * this.minDistancePercentage;
			this.chestSource.pitch = this.legpitch;
			this.chestSource.volume = Mathf.Lerp(this.chestSource.volume, this.relationship * 20f * (this.chestDisplacement - 0.001f), Time.deltaTime * 8f);
			num += this.hipSource.volume;
		}
		if (num > 1f)
		{
			return;
		}
		if (this.lefthandSource)
		{
			this.lefthandDisplacement = Vector3.Distance(this.L2hand, this.Lhand.position) / this.modifier;
			this.L2hand = this.Lhand.position;
			this.lefthandSource.maxDistance = this.lefthandDistance * this.scale;
			this.lefthandSource.minDistance = this.lefthandSource.maxDistance * this.minDistancePercentage;
			this.lefthandSource.pitch = this.modpitch;
			this.lefthandSource.volume = Mathf.Lerp(this.lefthandSource.volume, this.relationship * 14f * (this.lefthandDisplacement - 0.001f), Time.deltaTime * 8f);
		}
		if (this.righthandSource)
		{
			this.righthandDisplacement = Vector3.Distance(this.R2hand, this.Rhand.position) / this.modifier;
			this.R2hand = this.Rhand.position;
			this.righthandSource.maxDistance = this.righthandDistance * this.scale;
			this.righthandSource.minDistance = this.righthandSource.maxDistance * this.minDistancePercentage;
			this.righthandSource.pitch = this.modpitch;
			this.righthandSource.volume = Mathf.Lerp(this.righthandSource.volume, this.relationship * 14f * (this.righthandDisplacement - 0.001f), Time.deltaTime * 8f);
		}
		if (this.leftfootSource)
		{
			this.leftfootDisplacement = Mathf.Abs(this.L2foot.y - this.Lfoot.position.y) / this.modifier;
			this.L2foot = this.Lfoot.position;
			this.leftfootSource.maxDistance = this.leftfootDistance * this.scale;
			this.leftfootSource.minDistance = this.leftfootSource.maxDistance * this.minDistancePercentage;
			this.leftfootSource.pitch = this.modpitch;
			this.leftfootSource.volume = Mathf.Lerp(this.leftfootSource.volume, this.relationship * 64f * (this.leftfootDisplacement - 0.00155f), Time.deltaTime * 8f);
		}
		if (this.rightfootSource)
		{
			this.rightfootDisplacement = Mathf.Abs(this.R2foot.y - this.Rfoot.position.y) / this.modifier;
			this.R2foot = this.Rfoot.position;
			this.rightfootSource.maxDistance = this.rightfootDistance * this.scale;
			this.rightfootSource.minDistance = this.rightfootSource.maxDistance * this.minDistancePercentage;
			this.rightfootSource.pitch = this.modpitch;
			this.rightfootSource.volume = Mathf.Lerp(this.rightfootSource.volume, this.relationship * 64f * (this.rightfootDisplacement - 0.00155f), Time.deltaTime * 8f);
		}
		if (this.leftlegSource)
		{
			this.leftlegDisplacement = Vector3.Distance(this.L2leg, this.Lleg.position) / this.modifier;
			this.L2leg = this.Lleg.position;
			this.leftlegSource.maxDistance = this.leftlegDistance * this.scale;
			this.leftlegSource.minDistance = this.leftlegSource.maxDistance * this.minDistancePercentage;
			this.leftlegSource.pitch = this.legpitch;
			this.leftlegSource.volume = Mathf.Lerp(this.leftlegSource.volume, this.relationship * 12.5f * (this.leftlegDisplacement - 0.000875f), Time.deltaTime * 7f);
		}
		if (this.rightlegSource)
		{
			this.rightlegDisplacement = Vector3.Distance(this.R2leg, this.Rleg.position) / this.modifier;
			this.R2leg = this.Rleg.position;
			this.rightlegSource.maxDistance = this.rightlegDistance * this.scale;
			this.rightlegSource.minDistance = this.rightlegSource.maxDistance * this.minDistancePercentage;
			this.rightlegSource.pitch = this.legpitch;
			this.rightlegSource.volume = Mathf.Lerp(this.rightlegSource.volume, this.relationship * 12.5f * (this.rightlegDisplacement - 0.000875f), Time.deltaTime * 7f);
		}
	}

	// Token: 0x060010EC RID: 4332 RVA: 0x0007D19C File Offset: 0x0007B39C
	private AudioSource CreateAudioSource(Transform bone)
	{
		AudioSource audioSource = bone.gameObject.AddComponent<AudioSource>();
		audioSource.dopplerLevel = 0f;
		audioSource.spatialBlend = 1f;
		audioSource.volume = 1f;
		audioSource.outputAudioMixerGroup = SoundManager.mg_windG;
		audioSource.loop = true;
		return audioSource;
	}

	// Token: 0x040015E1 RID: 5601
	private Animator anim;

	// Token: 0x040015E2 RID: 5602
	private Player player;

	// Token: 0x040015E3 RID: 5603
	private Giantess giantess;

	// Token: 0x040015E4 RID: 5604
	private int animationSpeedHash;

	// Token: 0x040015E5 RID: 5605
	private AudioSource lefthandSource;

	// Token: 0x040015E6 RID: 5606
	private AudioSource righthandSource;

	// Token: 0x040015E7 RID: 5607
	private AudioSource leftlegSource;

	// Token: 0x040015E8 RID: 5608
	private AudioSource rightlegSource;

	// Token: 0x040015E9 RID: 5609
	private AudioSource leftfootSource;

	// Token: 0x040015EA RID: 5610
	private AudioSource rightfootSource;

	// Token: 0x040015EB RID: 5611
	private AudioSource hipSource;

	// Token: 0x040015EC RID: 5612
	private AudioSource headSource;

	// Token: 0x040015ED RID: 5613
	private AudioSource chestSource;

	// Token: 0x040015EE RID: 5614
	private static AudioClip handwind;

	// Token: 0x040015EF RID: 5615
	private static AudioClip legwind;

	// Token: 0x040015F0 RID: 5616
	private static AudioClip footwind;

	// Token: 0x040015F1 RID: 5617
	private static AudioClip hipwind;

	// Token: 0x040015F2 RID: 5618
	private static AudioClip headwind;

	// Token: 0x040015F3 RID: 5619
	private static AudioClip chestwind;

	// Token: 0x040015F4 RID: 5620
	public float minDistancePercentage = 0.015f;

	// Token: 0x040015F5 RID: 5621
	public float lefthandDistance = 10000f;

	// Token: 0x040015F6 RID: 5622
	public float righthandDistance = 10000f;

	// Token: 0x040015F7 RID: 5623
	public float leftfootDistance = 10000f;

	// Token: 0x040015F8 RID: 5624
	public float rightfootDistance = 10000f;

	// Token: 0x040015F9 RID: 5625
	public float leftlegDistance = 10000f;

	// Token: 0x040015FA RID: 5626
	public float rightlegDistance = 10000f;

	// Token: 0x040015FB RID: 5627
	public float hipDistance = 10000f;

	// Token: 0x040015FC RID: 5628
	public float headDistance = 10000f;

	// Token: 0x040015FD RID: 5629
	public float chestDistance = 10001f;

	// Token: 0x040015FE RID: 5630
	public float pitch = 1f;

	// Token: 0x040015FF RID: 5631
	public Transform lefthand;

	// Token: 0x04001600 RID: 5632
	public Transform Lhand;

	// Token: 0x04001601 RID: 5633
	public Vector3 L2hand;

	// Token: 0x04001602 RID: 5634
	public Transform righthand;

	// Token: 0x04001603 RID: 5635
	public Transform Rhand;

	// Token: 0x04001604 RID: 5636
	public Vector3 R2hand;

	// Token: 0x04001605 RID: 5637
	public Transform leftfoot;

	// Token: 0x04001606 RID: 5638
	public Transform Lfoot;

	// Token: 0x04001607 RID: 5639
	public Vector3 L2foot;

	// Token: 0x04001608 RID: 5640
	public Transform rightfoot;

	// Token: 0x04001609 RID: 5641
	public Transform Rfoot;

	// Token: 0x0400160A RID: 5642
	public Vector3 R2foot;

	// Token: 0x0400160B RID: 5643
	public Transform leftleg;

	// Token: 0x0400160C RID: 5644
	public Transform Lleg;

	// Token: 0x0400160D RID: 5645
	public Vector3 L2leg;

	// Token: 0x0400160E RID: 5646
	public Transform rightleg;

	// Token: 0x0400160F RID: 5647
	public Transform Rleg;

	// Token: 0x04001610 RID: 5648
	public Vector3 R2leg;

	// Token: 0x04001611 RID: 5649
	public Transform hips;

	// Token: 0x04001612 RID: 5650
	public Transform Thips;

	// Token: 0x04001613 RID: 5651
	public Vector3 T2hips;

	// Token: 0x04001614 RID: 5652
	public Transform head;

	// Token: 0x04001615 RID: 5653
	public Transform Thead;

	// Token: 0x04001616 RID: 5654
	public Quaternion headRotation;

	// Token: 0x04001617 RID: 5655
	public Transform chest;

	// Token: 0x04001618 RID: 5656
	public Transform Tchest;

	// Token: 0x04001619 RID: 5657
	public Vector3 T2chest;

	// Token: 0x0400161A RID: 5658
	private float pitchAdjust;

	// Token: 0x0400161B RID: 5659
	private float lefthandDisplacement;

	// Token: 0x0400161C RID: 5660
	private float righthandDisplacement;

	// Token: 0x0400161D RID: 5661
	private float leftfootDisplacement;

	// Token: 0x0400161E RID: 5662
	private float rightfootDisplacement;

	// Token: 0x0400161F RID: 5663
	private float leftlegDisplacement;

	// Token: 0x04001620 RID: 5664
	private float rightlegDisplacement;

	// Token: 0x04001621 RID: 5665
	private float hipDisplacement;

	// Token: 0x04001622 RID: 5666
	private float headRotationalDisplacement;

	// Token: 0x04001623 RID: 5667
	private float chestDisplacement;

	// Token: 0x04001624 RID: 5668
	private float modifier;

	// Token: 0x04001625 RID: 5669
	private float relationship;

	// Token: 0x04001626 RID: 5670
	private float scale;

	// Token: 0x04001627 RID: 5671
	private float speed;

	// Token: 0x04001628 RID: 5672
	private float size;

	// Token: 0x04001629 RID: 5673
	private float modpitch;

	// Token: 0x0400162A RID: 5674
	private float legpitch;

	// Token: 0x0400162B RID: 5675
	private float headpitch;
}
